//
//  REBaseTableViewController.swift
//  GoGlobalis
//
//  Created by goglobails on 2018/10/8.
//  Copyright © 2018年 Webkul. All rights reserved.
//

import UIKit
import SnapKit

open class REBaseTableViewController: REBaseViewController {
    
    public var tableViewStyle: UITableViewStyle = .plain
    public var tableEdgeInset: UIEdgeInsets = UIEdgeInsets.zero
    public var separatorColor: UIColor = REHexRGB(0xdbdbdb)
    public var separatorInset: UIEdgeInsets = UIEdgeInsets.zero
    public var hidenSeparator: Bool = false
    public var page: Int = 1
    
    override open func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    public lazy var tableView : UITableView = {
        let view = UITableView(frame: CGRect.zero, style: tableViewStyle)
        view.backgroundColor = REViewBackgroundColor()
        view.tableFooterView = UIView()
        if hidenSeparator {
            view.separatorStyle = .none
        } else {
            view.separatorColor = separatorColor
            view.separatorInset = separatorInset
        }
        self.view.addSubview(view)
        self.view.sendSubview(toBack: view)
        
        var edgeInsets = tableEdgeInset
        
        if #available(iOS 11.0, *) {
            view.contentInsetAdjustmentBehavior = .never
            
            edgeInsets.top = (UIApplication.shared.keyWindow?.safeAreaInsets.top)!
            edgeInsets.left = (UIApplication.shared.keyWindow?.safeAreaInsets.left)!
            edgeInsets.right = (UIApplication.shared.keyWindow?.safeAreaInsets.right)!
            edgeInsets.bottom = (UIApplication.shared.keyWindow?.safeAreaInsets.bottom)!
        }
        view.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(edgeInsets.left)
            make.right.equalToSuperview().offset(-edgeInsets.right)
            make.top.equalToSuperview().offset(edgeInsets.top)
            make.bottom.equalToSuperview().offset(-edgeInsets.bottom)
        }
        return view
    }()
    

}
